package models.mappers;

import java.util.List;

import models.User;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;

import vos.UserInfoSearchVo;

public interface UserMapper {
	/**
	 * 根据ID查询身份证号
	 *
	 * @Title: selectById 
	 * @param id
	 * @return
	 * @return: User
	 */
	 @Select("select u.* from userinfo u where u.idcard=#{id}")
	    User selectById(String id);
	 /**
	  * 插入新用户
	  *
	  * @Title: insert 
	  * @param user
	  * @return: void
	  */
	 @Insert("insert into "
			+ User.TABLE_NAME
			+ "(idcard,password,username,sex,phone,birthdate,address,salt,createtime,createway,workaddress,lifestyle,race,bloodtype,rhfactor) "
			+ "values(#{idcard},#{password},#{username},#{sex},#{phone},#{birthdate},#{address},#{salt},#{createtime},#{createway},#{workaddress},#{lifestyle},#{race},#{bloodtype},#{rhfactor})")
	 void insert(User user);
	 /**
	  * 更新用户信息
	  *
	  * @Title: update 
	  * @param user
	  * @return: void
	  */
	 @Update("update "
	 		+ User.TABLE_NAME 
	 		+" set username=#{username},phone=#{phone},birthdate=#{birthdate},"
	 		+ "address=#{address},modifytime=#{modifytime},workaddress=#{workaddress},"
	 		+ "lifestyle=#{lifestyle},race=#{race},bloodtype=#{bloodtype},rhfactor=#{rhfactor} "
	 		+ "where idcard=#{idcard}")
	 void update(User user);
	 /**
	  * 重置密码
	  *
	  * @Title: update 
	  * @param user
	  * @return: void
	  */
	 @Update("update "
		 		+ User.TABLE_NAME 
		 		+" set password=#{password} where idcard=#{idcard}")
		 void rePassword(User user);
	 /**
	  * 根据筛选条件统计用户数量
	  *
	  * @Title: countUserInfo 
	  * @param vo
	  * @return
	  * @return: long
	  */
	long countUserInfo(UserInfoSearchVo vo);
	/**
	 * 获取用户列表
	 *
	 * @Title: listUserInfo 
	 * @param vo
	 * @return
	 * @return: List<User>
	 */
	List<User> listUserInfo(UserInfoSearchVo vo);
	/**
	 * 更新用户信息
	 *
	 * @Title: updateUserInfo 
	 * @param user
	 * @return: void
	 */
	@Update("update "
			+ User.TABLE_NAME
			+" set username=#{username},birthdate=#{birthdate},"
			+ "phone=#{phone},address=#{address},sickness=#{sickness},"
			+ "issmoke=#{issmoke},memberrate=#{memberrate},"
			+ "workaddress=#{workaddress},lifestyle=#{lifestyle},"
			+ "race=#{race},bloodtype=#{bloodtype},rhfactor=#{rhfactor}"
			+ " where idcard=#{idcard}")
	void updateUserInfo(User user);
	/**
	 * 根据筛选条件获取excel数据
	 *
	 * @Title: exportXls 
	 * @param vo
	 * @return
	 * @return: List<User>
	 */
	List<User> exportXls(UserInfoSearchVo vo);
	/**
	 * 根据身份证号查询用户是否存在
	 *
	 * @Title: selectidcardById 
	 * @param id
	 * @return
	 * @return: String
	 */
	@Select("select 1 from userinfo where idcard=#{id}")
	String selectidcardById(String id);
}
